﻿@model FB.Providers.EmployeeInfo.Employee
@{
    ViewBag.Title = "员工添加";
    Layout = "~/Views/Shared/_ContentLayout.cshtml";
}
@section HeadIncluder 
{
      <link href='@Url.Content("~/Content/public.css")' rel="stylesheet" />
    <link href='@Url.Content("~/Content/con_style.css")' rel="stylesheet" />
    <link rel="stylesheet" type="text/css" href=@Url.Content("~/Scripts/skins/default.css")   />
}
@using (Html.BeginForm("Save", "Employee", FormMethod.Post, new { id = "frm" }))
{
  <div>
       @Html.HiddenFor(model => model.EMPCode, new { id = "txtEMPCode" })
            @Html.HiddenFor(model => model.CreatedBy, new { id = "txtCreatedBy" })
        <div class="dbox_d">
            <table width="100%" class="dbox_con"> 
        <tr  >
            <td class="text_s">姓名：</td>
            <td >
                <input id="txtFirstName" name="ChineseName" value="@Model.ChineseName"   class="validate[required]" type="text" /></td> 
                 <td class="text_s">性别：</td>
            <td class="lable">
                <select id="txtGender" name="Gender">
                    <option value="M">男</option>
                    <option value="W">女</option>
                </select>
            </td>
                      <td class="lable" rowspan="5" style="text-align:center;">
                <img  id="TenantImg" alt="" src="/Employee/GetImg?id=@Model.UserID" style="width:120px;height:180px"/><br />
                              <input id="Imgfile" name="Imgfile" type="file" value="预览" onchange="ChangeImage(this,'#TenantImg')" />
                </td>
        </tr>
        <tr> 
            <td class="text_s">员工编号：</td>
            <td class="lable">
                <input id="txtRefCode" name="RefCode" value="@Model.RefCode"   class="validate[required]" type="text" /></td>
            <td class="text_s">登录名:</td>
            <td class="lable">
                <input id="txtUserName" name="UserName" value="@Model.UserName"   class="validate[required]" type="text" /></td>
        </tr> 
        <tr>
            <td class="text_s">Email:</td>
            <td class="lable">
                <input id="txtEmail" name="Email" value="@Model.Email"   class="validate[required]" type="text" /></td>
            <td class="text_s">员工类型:</td>
            <td class="lable">
                @Html.DropDownListFor(model => model.EMPType, (IEnumerable<SelectListItem>)ViewBag.EmployeeTypeList, new { id = "txtEMPType" })
            </td>
        </tr>
        <tr>
             <td class="text_s">联系电话：
            </td>
            <td class="lable">
                <input id="txtMobile" name="Mobile" type="text" value='@Model.Mobile' />
            </td>
            <td class="text_s">内部电话:</td>
            <td   class="lable" >
               <input id="ExtensionNo" name="ExtensionNo" type="text" value='@Model.ExtensionNo' />
            </td>
           
        </tr>
                  <tr>
            <td class="text_s">入职时间:</td>
            <td class="lable" style="padding-left:6px;" colspan="3">
                <input id="txtTerminationDate" name="TerminationDate" type="text" value='@(Model.TerminationDate.HasValue ? Model.TerminationDate.Value.ToString("yyyy-MM-dd") : "")' />
            </td>
             
        </tr>
        <tr>
            <td colspan="5">
                <div id="tabstrip" style="min-height: 300px;">
                    <ul>
                        <li class="k-state-active">职务信息
                        </li> 
                        <li>直属上司
                        </li> 
                    </ul>
                    <div>
                      <table id="tbTeamList" class="border tb_form dbox_con" style="padding-left:0px;">
                            <thead>
                                <tr  style="padding-left:0px;">
                                    <td  style="text-align: left; width:80px">公司：</td>
                                    <td style="padding-left:0px;">
                                            @{
                                    Html.RenderPartial("UCCompanySelectTree", (IList<FB.Providers.EmployeeInfo.Company>)ViewBag.CompanyList);
                                            }
                                       </td>
                                       <td  style="text-align: left; width:80px"> 部门：</td>
                                        <td style="padding-left:0px;">
                                        <span class="deptConatainer"  style=" margin-left: 5px;" > @{
                            Html.RenderPartial("UCDepartmentSelectTree", (IList<FB.Providers.EmployeeInfo.Department>)ViewBag.DepartmentList);
                                        } 
                                        </span>
                                        </td>
                                        <td  style="text-align: left; width:80px">分组：</td>
                                        <td style="padding-left:0px;">
                                    <select id="txtTeamList" style="width:120px;" name="TeamList"  >
                                        </select>
                                            </td>
                                        <td style="text-align: left; width:80px">岗位：</td>
                                    <td style="padding-left:0px;">
                                           @{
                                        Html.RenderPartial("UCPositionSelectTree", (IList<FB.Providers.EmployeeInfo.Position>)ViewBag.PositionList);
                                        }  
                                    </td>
                                    <td style="text-align: right; width:80px">
                                        <div class="bar_btn f_btnc">
                                            <button  name="del" type="button" onclick="addTeam()" class="fj btn_c3 btn_s ">添加</button>
                                        </div>
                                    </td>
                                </tr>
                            </thead>
                            <tr >
                                <th style="background:#E6EFF8;">公司</th>
                                <th style="background:#E6EFF8;">公司编码</th>
                                <th style="background:#E6EFF8;">部门</th>
                                <th style="background:#E6EFF8;">部门编码</th>
                                <th style="background:#E6EFF8;">分组</th>
                                <th style="background:#E6EFF8;">分组编码</th>
                                <th style="background:#E6EFF8;">岗位名称</th>
                                <th style="background:#E6EFF8;">岗位编码</th> 
                                <th style="background:#E6EFF8;">操作</th>
                            </tr>
                          @{
                            
                            foreach (var item in Model.PostDetails)
                            {
                                <tr>
                                    <td>@item.Company.Name</td>
                                    <td>@item.Company.COMCode</td>
                                    <td>@(item.Department != null ? item.Department.Name : "")</td>
                                    <td>@item.DEPTCode</td>
                                    <td>@(item.Team != null ? item.Team.Name : "")</td>
                                    <td>@item.TEAMCode</td>
                                    <td>@item.Position.Name</td>
                                    <td>@item.POSCode</td>
                                    <td>
                                        <div class="bar_btn f_btnc">
                                            <button  name="del" type="button" onclick="onRefresh()" class="fj btn_c3 btn_s del">删除</button>
                                        </div>
                                </tr>
                            }
                          }
                        </table>

                    </div>
                     
                    <div style="min-height: 200px;"> 
                        <table id="tbSuperList" class="border tb_form" style="margin-left: 0px;">
                              <thead>
                                <tr> 
                                    <td colspan="3" style="text-align: right;">
                                          <div class="bar_btn f_btnc">
                                            <button  name="del" type="button" onclick="addSuper()" class="fj btn_c3 btn_s ">添加</button>
                                        </div>
                                    </td>
                                </tr>
                            </thead>
                            <tr>
                                <th style="display:none">系统编号</th>
                                <th style="background:#E6EFF8;">员工编号</th>
                                <th style="background:#E6EFF8;">名称</th>
                                <th style="background:#E6EFF8;">操作</th>
                            </tr>
                            @foreach (var item in Model.Supervisors)
                            {
                                <tr>
                                    <td style="display:none">@item.EMPCode</td>
                                    <td>@item.RefCode</td>
                                    <td>@item.ChineseName</td> 
                                    <td>
                                         <div class="bar_btn f_btnc">
                                            <button  name="del" type="button" onclick="onRefresh()"  class="fj btn_c3 btn_s del">删除</button>
                                        </div>
                                    </td>
                                </tr>
                            }
                        </table>
                    </div>
                </div>
            </td>
        </tr>
    </table>
    </div>
      </div>
    <div class="btn_d">
        <span class="btn_s btn_c1"><a href="javascript:void(0)" onclick="bnt_reset()" target="_blank">重置</a></span>
        <span class="btn_s btn_c1"><a  href="javascript:void(0)" id="subbtn"  target="_blank">确定</a></span>
        <span class="btn_s btn_c2"><a  href="javascript:void(0)" onclick="cancel()" target="_blank">取消</a></span>
    </div> 
     
    <script src=@Url.Content("/Scripts/jquery.form.js") type="text/javascript"></script>
    <script type="text/javascript">
        function addTeam() {
            var postCode = $("#PositionList").val();
            var compCode = $("#tbTeamList .CompanyList").val();
            if (postCode == null || postCode == "") {
                alert("你还没选择岗位!")
                return;
            }
            if (compCode == null || compCode == "") {
                alert("你还没选择公司!")
                return;
            }
            var teamCode = $("#txtTeamList").val();
            var teamName = $("#txtTeamList option:selected").html();
            var deptCode = $("#tbTeamList .DeparmentList").val();
        
           
            var deptName = $("#tbTeamList .DeparmentList option:selected").attr("DepartmentName");
            var compName = $("#tbTeamList .CompanyList option:selected").attr("CompanyName");
            var PositionName = $("#PositionList option:selected").attr("PositionName");
            if (deptName == undefined) deptCode = "";
            if (teamName == undefined) teamName = "";
            if (teamCode == undefined) teamCode = "";
            if (teamName == undefined) teamName = "";
            var str = '<tr>';
            str = str + '<td>' + compName + '</td>';
            str = str + '<td>' + compCode + '</td>';
            str = str + '<td>' + deptName + '</td>';
            str = str + '<td>' + deptCode + '</td>';
            str = str + '<td>' + teamName + '</td>';
            str = str + '<td>' + teamCode + '</td>';
            str = str + '<td>' + PositionName + '</td>';
            str = str + '<td>' + postCode + '</td>';
            str = str + '<td><input name="delRow" class="fj btn_c3 btn_s del" style="width:80px"  type="button" value="删除" /></td>';
            str = str + ' </tr>';
            $(str).appendTo("#tbTeamList");
        } 
        function addSuper() {
            var url = '@Url.Action("EmployeeSelect", "Employee")';
            OpenSelectUserPop(url, RefreshValue);
         
        }

        function RefreshValue(selectPostList) {
            if (selectPostList != null || selectPostList != undefined) {
                $.each(selectPostList, function (i, val) {
                    var str = '<tr>';
                    str = str + '<td>' + val.EMPCode + '</td>';
                    str = str + '<td>' + val.Name + '</td>';
                    str = str + '<td><input name="delRow" class="fj btn_c3 btn_s del"  style="width:80px" type="button" value="删除" /></td>';
                    str = str + ' </tr>';
                    $(str).appendTo("#tbSuperList");
                });
            }
        }
        function GetTeamList() {
            var url = '@Url.Action("GetTeams", "Employee")' + '?DepartmentID=' + $(".DeparmentList").val();
             $("#txtTeamList").empty();
             $.post(url, function (data) {
                 $.each(data, function (i, item) {
                     $("<option value='" + item.TEAMCode + "'>" + item.Name + "</option>").appendTo("#txtTeamList");
                 });
             });
        }
        function GetDepartmentList() {
            var url = '@Url.Action("GetDeparmentList", "Employee")' + '?CompanyID=' + $(".CompanyList").val();
             $.post(url, function (data) {
                 $(".deptConatainer").html(data);
                 $(".DeparmentList").trigger("change");
             });
        }
        function bnt_reset() {
            $("#frm")[0].reset();
        };
        function cancel() {
            window.top.oDG.close();
        };
        $(function () {
            $("#tabstrip").kendoTabStrip();
            $(".del").live("click", function () {
                $(this).parent().parent().remove();
            }); 
            $(".CompanyList").live("change", function () {
                GetDepartmentList();
            }); 
            $(".DeparmentList").live("change", function () {
                GetTeamList();
            });
            $(".CompanyList").trigger("change");
            $("#txtTerminationDate").kendoDatePicker({ format: "yyyy-MM-dd" });
            $("#frm").validationEngine({ promptPosition: "topLeft" });
            $("#subbtn").click(function () { 
                var flag = $("#frm").validationEngine({ promptPosition: "topLeft" });
                if (!flag) return false;
                var EmployeeInPositions = new Array(); 
                var Supervisors = new Array();  
                rows = $("#tbSuperList tr:gt(1)");
                $.each(rows, function (i, item) {
                    var cols = $(item).find("td");
                    var obj = new Object();
                    obj.EMPCode = cols[0].innerHTML; 
                    Supervisors.push(obj);
                });
                rows = $("#tbTeamList tr:gt(1)");
                $.each(rows, function (i, item) {
                    var cols = $(item).find("td");
                    var obj = new Object(); 
                    obj.COMCode = cols[1].innerHTML;
                    if(cols[3].innerHTML!="")
                        obj.DEPTCode = cols[3].innerHTML;
                    if (cols[5].innerHTML != "")
                    obj.TEAMCode = cols[5].innerHTML;
                    obj.POSCode = cols[7].innerHTML;
                    obj.CropTitle = cols[0].innerHTML + " -" + cols[6].innerHTML;
                    if (cols[2].innerHTML!="")
                        obj.CropTitle = cols[2].innerHTML + " -" + cols[6].innerHTML;
                    EmployeeInPositions.push(obj);
                });
         
                var options = {
                    data: {
                        strEmployeeInPositions: JSON.stringify(EmployeeInPositions),
                        strSupervisors: JSON.stringify(Supervisors)
                    },
                    success: function (data) {
                        if (data == "登录名重复" || data == "邮件名重复") {
                            alert(data)
                        }
                        else {
                            window.top.refresh();
                            window.top.oDG.close();
                        }
                    }
                };
                $("#frm").ajaxSubmit(options);
            });
        });

        function ChangeImage(fileId, imageId) {
            var options = {
                url: "/Employee/UploadImage",
                type: "post",
                success: function (responseText) {
                    var d = new Date();
                    $("#TenantImg")[0].src = "/Employee/GetUploadImage"+"?dt="+d.getTime();                  

                }
            }
            $("#frm").ajaxSubmit(options);
        }
    </script>
}


